<?php

include_once "../../lib/init.php";

if ($_POST['Submit']) {
	    $id = $_REQUEST['hid'];
		$name = $_POST['name'];
		$password = md5($_POST['password']);
		$npassword = md5($_POST['newpassword']);
		$npasswords = md5($_POST['newpassword1']);

	$sql="select regpawd,regname from tx_user where id='$id'";
	//创建一个sqlhelper 对象
	$sqlHelper = new MySqlHelper();
	$res=$sqlHelper->execute_dql($sql);
	if ($row=$res->fetch_assoc()) {
		# 比对密码
//		var_dump($row);
		if ($password == $row['regpawd']) {


			//$row =array_values($res);

//			exit();

//	echo "<pre>";
//	var_dump($res);
//	echo "</pre>";
			# 比对密码
				# code...
//			echo $name, $password;
//	if ($name != " " || $password !=" " ||$npassword !=" " ||$npasswords!=" " ) {
//		echo "<script>alert('文本框为空，请重新填写');</script>";
//		require_once ROOT . "/view/admin/user_edit.php";
//
//		echo $id."</br>";
//
//		//exit();
//		echo $name, $password;
//		exit();
//	}
				//$sql="select * from tx_user  where regname='".$_POST['name']."' and regpawd='".$_POST['password']."' ";
				$sql1 = "select regpawd from tx_user where regpawd='" . $password . "' and id='$id'";
				$mySqlHelper = new MySqlHelper();
				$res = $mySqlHelper->getRowsNum($sql1);

				if ($res < 1) {
					echo "<script>alert('您输入的密码不正确，请重新输入');history.back();</script>";
				} else {
					//$sql = "update tx_user set regname='$name',regpawd='$npassword' where id='$id'";
					$sql = "update tx_user set regname='" . $name . "', regpawd='" . $npassword . "' where id=$id";
					$res2 = $mySqlHelper->execute_dql($sql);
					if ($res2 == true) {
						echo "<script>alert('密码更改成功')</script>";
						echo "<script>alert('更新成功');</script>";
						require_once ROOT . "/view/admin/user_list.php";
					}
				}
			}else{
			echo "<script>alert('您输入的密码不正确，请重新输入');history.back();</script>";
		}
		}

}